package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.*;
import com.ruoyi.system.dto.*;
import com.ruoyi.system.service.IMemberService;
import com.ruoyi.system.service.IPointService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.success;


/**
 * 积分
 */
@RestController
@RequestMapping("/system/points")
public class PointsController extends BaseController {
    @Autowired
    private IPointService pointService;


    /**
     * 新增积分配置
     */
    @ApiOperation(value = "新增积分配置")
    @PostMapping(value = "/addOrUpdate")
    public AjaxResult addOrUpdate(@RequestBody PointsConfigVo pointsConfigVo)
    {
        return success(pointService.addOrUpdate(pointsConfigVo));
    }

    /**
     * 积分配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String name)
    {
        startPage();
        List<PointsConfigDTO> dto =  pointService.getList(name);
        // 获取准确的总数
        int total = pointService.countList(name);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setMsg("查询成功");
        rspData.setRows(dto);
        rspData.setTotal(total);
        return rspData;
    }


    /**
     * 用户积分日志列表
     */
    @GetMapping("/userPointsLogList")
    public TableDataInfo userPointsLogList(UserPointsListVo userPointsListVo)
    {
        startPage();
        List<UserPointsLogDTO> dto =  pointService.getUserPointsLogList(userPointsListVo);
        // 获取准确的总数
        int total = pointService.getUserPointsLogCount(userPointsListVo);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setMsg("查询成功");
        rspData.setRows(dto);
        rspData.setTotal(total);
        return rspData;
    }


    /**
     * 用户积分列表
     */
    @GetMapping("/userPointsList")
    public TableDataInfo userPointsList(UserPointsListVo userPointsListVo)
    {
        startPage();
        List<UserPointsDTO> dto =  pointService.getUserPointsList(userPointsListVo);
        // 获取准确的总数
        int total = pointService.getUserPointsCount(userPointsListVo);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setMsg("查询成功");
        rspData.setRows(dto);
        rspData.setTotal(total);
        return rspData;
    }


    /**
     * 积分配置列表详情
     */
    @GetMapping("/info/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(pointService.getInfo(id));
    }

}
